package com.hlw.hr_man.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hlw.hr_man.Model.Absent;
import com.hlw.hr_man.service.AbsentService;
import com.hlw.hr_man.serviceImpl.AbsentServiceImpl;

/**
 * 
 * @ClassName: AddAbsentController
 * @Description: 处理添加缺勤记录操作
 * @author 唐明
 * @date 2016年9月20日 上午9:47:57
 *
 */
public class AddAbsentController extends HttpServlet{

	/**
	 * @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
	 */ 
	private static final long serialVersionUID = 1L;
	
	AbsentService aService = new AbsentServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		//获取要添加的信息
		String e_number = req.getParameter("e_number");
		String starttime = req.getParameter("starttime");
		String endtime = req.getParameter("endtime");
		int e_id = Integer.parseInt(req.getParameter("e_id"));
		Absent absent = new Absent(0, e_id, starttime, endtime);
		//添加是否成功
		boolean flag = aService.addAbsent(absent);
		PrintWriter pw = resp.getWriter();
		
		if (flag) {
			//操作成功  返回员工编号
			pw.write(e_number);
		} else {
			//操作失败 返回"0"
			pw.write("0");
		}
	}
}
